package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsSiteVisitorMessage;
import com.ruoyi.cms.service.ICmsSiteVisitorMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 游客留言Controller
 *
 * @author ruoyi
 * @date 2022-09-02
 */
@RestController
@RequestMapping("/cms/message")
public class CmsSiteVisitorMessageController extends BaseController {
    @Autowired
    private ICmsSiteVisitorMessageService cmsSiteVisitorMessageService;

    /**
     * 查询游客留言列表
     */
    @PreAuthorize("@ss.hasPermi('cms:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsSiteVisitorMessage cmsSiteVisitorMessage) {
        startPage();
        List<CmsSiteVisitorMessage> list = cmsSiteVisitorMessageService.selectCmsSiteVisitorMessageList(cmsSiteVisitorMessage);
        return getDataTable(list);
    }

    /**
     * 导出游客留言列表
     */
    @PreAuthorize("@ss.hasPermi('cms:message:export')")
    @Log(title = "游客留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsSiteVisitorMessage cmsSiteVisitorMessage) {
        List<CmsSiteVisitorMessage> list = cmsSiteVisitorMessageService.selectCmsSiteVisitorMessageList(cmsSiteVisitorMessage);
        ExcelUtil<CmsSiteVisitorMessage> util = new ExcelUtil<CmsSiteVisitorMessage>(CmsSiteVisitorMessage.class);
        util.exportExcel(response, list, "游客留言数据");
    }

    /**
     * 获取游客留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cmsSiteVisitorMessageService.selectCmsSiteVisitorMessageById(id));
    }

    /**
     * 新增游客留言
     */
    @PreAuthorize("@ss.hasPermi('cms:message:add')")
    @Log(title = "游客留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsSiteVisitorMessage cmsSiteVisitorMessage) {
        return toAjax(cmsSiteVisitorMessageService.insertCmsSiteVisitorMessage(cmsSiteVisitorMessage));
    }

    /**
     * 修改游客留言
     */
    @PreAuthorize("@ss.hasPermi('cms:message:edit')")
    @Log(title = "游客留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsSiteVisitorMessage cmsSiteVisitorMessage) {
        return toAjax(cmsSiteVisitorMessageService.updateCmsSiteVisitorMessage(cmsSiteVisitorMessage));
    }

    /**
     * 删除游客留言
     */
    @PreAuthorize("@ss.hasPermi('cms:message:remove')")
    @Log(title = "游客留言", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cmsSiteVisitorMessageService.deleteCmsSiteVisitorMessageByIds(ids));
    }
}
